﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bus.Bll;
using Bus.Model;

public partial class admin_logmanage : System.Web.UI.Page
{
    protected tb_log logbll = new tb_log();
    protected tb_custom cusbll = new tb_custom();
    protected tb_user userbll = new tb_user();
    protected UserModel um=null;
    protected CustomModel cm = null;
    protected LogModel lm = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitLoginfo();
        }
    }

    public string GetName(object userstr, object cusstr)
    {
        string str1 = userstr.ToString();
        string str2 = cusstr.ToString();
        try
        {
            if (str1 == "")
            {
                cm = cusbll.GetModel(int.Parse(str2));
                return cm.cname;
            }
            else
            {
                um = userbll.GetModel(int.Parse(str1));
                return um.username;
            }
        }
        catch (Exception e) {
            return "none";
        }

    }
    private void InitLoginfo()
    {
        try
        {

            userlist.PageSize = 30;
            userlist.RecordCount = logbll.GetRecordCount("");
            userrep.DataSource = logbll.GetListByPage("", "", (userlist.CurrentPageIndex - 1) * userlist.PageSize, userlist.CurrentPageIndex*userlist.PageSize);
            userrep.DataBind();
        }
        catch (Exception e) { }
    }
    protected void userlist_PageChanged(object sender, EventArgs e)
    {
        InitLoginfo();
    }
    protected void LinkButton1_click(object sender, EventArgs e)
    {
        LinkButton lbt = sender as LinkButton;
        int cid = int.Parse(lbt.CommandArgument);
        if (logbll.Delete(cid))
        {
            lm = new LogModel();
            lm.userid = int.Parse(Session["userid"].ToString());
            lm.op = "删除";
            lm.memo = "删除一个日志";
            lm.opdate = DateTime.Now;
            logbll.Add(lm);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除成功！');</script>");
            InitLoginfo();
        }
        else
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除失败！');</script>");
    }
}
